<#include "/common/common.ftl">
<@html>
<link rel="stylesheet" href="${path}/js/dojo/dojox/grid/resources/${theme}Grid.css">
<script type="text/javascript" src="${path}/js/dojo/dojo/inputForm.gzjs"></script>
<script type="text/javascript" src="${path}/js/dojo/dojo/naviGrid.gzjs"></script>
<script type="text/javascript">
	//	dojo.require("dijit.dijit");
	//	dojo.require("dijit.form.Form");
	//  dojo.require("dijit.form.Select");
	//	dojo.require("dijit.form.TextBox");
	//	dojo.require("dojox.data.QueryReadStore");
	//	dojo.require("widget.navgrid.NavGrid");
</script>
<@queryForm>
<div class="form-layout">
	<div class="cell">
		<div class="label">
			用户编号<@splitor/>
		</div>
		<div class="content">
			<input type="hidden" name="condition[0].propertyName" value="userCode"/>
			<input type="hidden" name="condition[0].operator" value="LIKE"/>
			<input type="hidden" name="condition[0].matchMode" value="BEFORE"/>
			<input dojoType="dijit.form.TextBox" name="condition[0].value" id="userCode"/>
		</div>
	</div>
	<div class="cell">
		<div class="label">
			名称<@splitor/>
		</div>
		<div class="content">
			<input type="hidden" name="condition[1].propertyName" value="userName"/>
			<input type="hidden" name="condition[1].operator" value="LIKE"/>
			<input type="hidden" name="condition[1].matchMode" value="ANYWHERE"/>
			<input dojoType="dijit.form.TextBox" name="condition[1].value" id="userName"/>
		</div>
	</div>
<@seniorQuery property="userName" index=2 />
</div>
<div class="clear"></div>
</@queryForm> <@toolbar/>
<div id="grid" dojoType="widget.navgrid.NavGrid"
     selectionMode="single" rowsPerPage="10"
     structure="layout" autoHeight="true">
</div>
</@html>
<script type="text/javascript">
	var store = new dojox.data.QueryReadStore({
		url : '${path}/system/user.list.do',
		requestMethod : "post"
	});
	var layout = [
		{
			cells : [
				[
					//new dojox.grid.cells.RowIndex({ width:"4%",name:"序号" }),
					{
						name : '用户编号',
						field : 'userCode',
						headerClasses:"gridHeader",
						width : "25%"
					},
					{
						name : '用户名称',
						field : 'userName',
						headerClasses:"gridHeader",
						width : "40%"
					},
					{
						name : '到期日期',
						field : 'expireDate',
						headerClasses:"gridHeader",
						width : "40%"
					}
				]
			]
		}
	];
	dojo.ready(function() {
		//事件注册
		//新增
		dojo.connect(dijit.byId("btnAdd"), "onClick", function() {
			parent.openDialog({
				id:"user/add",
				url:"${path}/system/user.load.do",
				title:'新增用户'
			});
		})
		//编辑
		dojo.connect(dijit.byId("btnEdit"), "onClick", function() {
			var selection = dijit.byId("grid").selection.getSelected();
			if (!selection || selection.length == 0) {
				window.parent.Error("您未选择数据！");
				return;
			}
			var id = store.getValue(selection[0], "id");
			parent.openDialog({
				id: "user/update",
				url : '${path}/system/user.load.do?targetUser.id=' + id,
				title : '修改用户',
				width : 800,
				height : 600
			});
		});
		//删除
		dojo.connect(dijit.byId("btnDelete"), "onClick", function() {
			var selection = dijit.byId("grid").selection.getSelected();
			if (!selection || selection.length == 0) {
				window.parent.Error("您未选择数据！");
				return;
			}
			var id = store.getValue(selection[0], "id");
			parent.Confirm({
				msg : "确认删除数据吗？",
				okCall : function() {
					dojo.xhrGet({
						url:"${path}/system/user.delete.do?targetUser.id=" + id,
						handleAs:"json",
						load:function(json) {
							window.parent.Info("删除成功！", function() {
								dijit.byId("grid").reload();
							});
						}
					})
				}
			})
		});
		//查询
		dojo.connect(dijit.byId("btnQuery"), "onClick", function() {
			dijit.byId("grid").setStore(store, dojo.formToObject(dojo.byId('queryForm')));
		});
		//注册响应函数
		parent.subscribe("${pageId!}", "user/save", null, function() {
			dijit.byId("grid").reload();
		});
	})
</script>
